import Router from './wx/router.js'
const Index = {
    ...Router,
    // 获取自定义tabBar
    getTabBar(index){
        if (typeof this.getTabBar === 'function' && this.getTabBar()) {
            this.getTabBar().setData({ selected: index  })
        }
    },
    // toast
    toast(title){ wx.showToast({icon:'none', title, duration: 2000  }) },
    toastSuccess(title){ wx.showToast({icon:'success', title, duration: 2000  }) },
    // modal
    modal({title='提示', content, success, cancel}){
        wx.showModal({ 
            title,
            content,
            success: res => {
                if(res.confirm){ success() }
                else if(res.cancel){ cancel()  }
            }
        })
    },
    // 本地缓存
    local(key,data){ 
        if(arguments.length === 2){
            wx.setStorage({ key, data })
        }else if(arguments.length === 1){
            return wx.getStorageSync(key)
        }
    },
    localRemove(key){
        wx.removeStorage(key)
    },
    localClear(){
        wx.clearStorage()
    }
}

export default Index